﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GUI
{
    public partial class CustomerForm : Form
    {
        public CustomerForm()
        {
            InitializeComponent();
        }

        private void buttonCreate_Click(object sender, EventArgs e)
        {   
            if (!string.IsNullOrWhiteSpace(textBoxCredit.Text) || !string.IsNullOrWhiteSpace(textBoxEmail.Text) || !string.IsNullOrWhiteSpace(textBoxHouse.Text) || !string.IsNullOrWhiteSpace(textBoxName.Text) || !string.IsNullOrWhiteSpace(textBoxPass.Text) || !string.IsNullOrWhiteSpace(textBoxPhone.Text) || !string.IsNullOrWhiteSpace(textBoxSsn.Text) || !string.IsNullOrWhiteSpace(textBoxStreet.Text) ||  !string.IsNullOrWhiteSpace(textBoxZip.Text))
            {
                try
                {
                    using(CustomerServiceRef.CustomerCtrClient csf = new CustomerServiceRef.CustomerCtrClient())
                    {
                        csf.CreateCustomer(textBoxSsn.Text, textBoxCredit.Text, textBoxName.Text, textBoxStreet.Text, Int32.Parse(textBoxHouse.Text), Int32.Parse(textBoxZip.Text), Int32.Parse(textBoxPhone.Text), textBoxEmail.Text, textBoxPass.Text);
                    }
                }
                catch (Exception e2)
                {
                    MessageBox.Show("Error-message: "+e2.Message, "ERROR!");
                }

                this.Close();
            }
            else
            {
                MessageBox.Show("Fill out all the information!" , "ERROR!");
            }
                
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
